package com.taxshare.manager.controller;

import com.taxshare.manager.service.UserService;
import com.taxshare.manager.view.dto.UserDTO;
import com.taxshare.manager.view.dto.UserRoleDTO;
import com.taxshare.mybatis.pager.PageRequest;
import com.taxshare.response.beans.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * @ClassName: UserController
 * @Description:
 * @author: luozhongyi
 * @date: 2021/1/29 14:14
 */
@RestController
@RequestMapping(value = "/user")
@Api(tags = "用户信息")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(method = RequestMethod.POST, value = "/add")
    @ApiOperation(notes = "用户信息", value = "新增")
    public Response add(@RequestBody UserDTO userDTO) throws NoSuchAlgorithmException {
        return userService.add(userDTO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/edit")
    @ApiOperation(notes = "用户信息", value = "编辑")
    public Response edit(@RequestBody UserDTO userDTO) {
        return userService.edit(userDTO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/delete")
    @ApiOperation(notes = "用户信息", value = "删除")
    public Response delete(@RequestBody UserDTO userDTO) {
        return userService.delete(userDTO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/info")
    @ApiOperation(notes = "用户信息", value = "查询")
    public Response info(@RequestBody PageRequest<UserDTO> query) {
        return userService.info(query);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/getOne")
    @ApiOperation(notes = "用户信息", value = "查询用户id")
    public Response getOne(@RequestParam("loginName") String loginName ) {
        return userService.getInfo(loginName);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/updateState")
    @ApiOperation(notes = "用户信息", value = "更改用户状态")
    public Response updateState(@RequestBody UserDTO userDTO) {
        return userService.updateState(userDTO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/resetPassword")
    @ApiOperation(notes = "用户信息", value = "重置密码")
    public Response resetPassword(@RequestBody UserDTO userDTO) throws NoSuchAlgorithmException {
        return userService.resetPassword(userDTO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/batchBindRole")
    @ApiOperation(notes = "用户信息", value = "批量绑定用户角色")
    public Response batchBindRole(@RequestBody UserRoleDTO userRoleDTO){
        return userService.batchBindRole(userRoleDTO);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/allInfo")
    @ApiOperation(notes = "用户信息", value = "全部用户")
    public Response allInfo() {
        return userService.allInfo();
    }


    @RequestMapping(method = RequestMethod.GET, value = "/userInfo")
    @ApiOperation(notes = "用户信息", value = "登录用户")
    public Response userInfo() {
        return userService.userInfo();
    }

    @RequestMapping(method = RequestMethod.POST, value = "/editPassword")
    @ApiOperation(notes = "用户信息", value = "更改用户密码")
    public Response editPassword(@RequestBody UserDTO userDTO) {
        return userService.editPassword(userDTO);
    }

}
